package com.lzx.study.controller;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class ChatClientController {
//    1.构造注入
    private final ChatClient dashScopeChatClient;

    public ChatClientController(ChatModel dashScopeChatModel) {
        this.dashScopeChatClient = ChatClient.builder(dashScopeChatModel).build();
    }

    @GetMapping("/hello/doChatClient")
    public String doChat(@RequestParam(name = "msg", defaultValue = "你是谁") String msg) {
        String result = dashScopeChatClient.prompt().system("你是一个叫罗旺的聊天机器人")
                .user(msg).call().content();
        log.info("result: {}", result);
        return result;
    }
}
